import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Solution2 {
    static List<Pair> listA=new ArrayList<>();
    static List<Pair> listB=new ArrayList<>();
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int cnt=s.nextInt();
        while(cnt-->0){
            int num=s.nextInt();
            int temp=num;
            while (temp-->0){
                listA.add(new Pair(s.nextInt(),s.nextInt()));
            }
            while (num-->0){
                listB.add(new Pair(s.nextInt(),s.nextInt()));
            }
            System.out.println(minDis(listA,listB));
        }
    }

    public static double distance(Pair a,Pair b){
        return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
    }

    public static double minDis(List<Pair> A,List<Pair> B){
        double min=Double.MAX_VALUE;
        int size=A.size();
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                double dist=distance(A.get(i),B.get(j));
                if(dist<min)
                    min=dist;
            }
        }
        double res=Math.sqrt(min);
        int res2=(int)res*1000;
        double resfinal=res2/1000;
        return Math.sqrt(resfinal);
    }

    static class Pair{
        double x;
        double y;

        public Pair(double x, double y) {
            this.x = x;
            this.y = y;
        }
    }

}
